package com.rickpan.enums;

/**
 * 权限枚举
 * 定义系统中所有可用的权限
 */
public enum Permission {
    
    // ==================== 基础权限 ====================

    // 用户级别权限
    BASIC_USER("basic:user", "基础用户权限"),
    ADMIN("admin", "管理员权限"),

    // 文件管理权限
    FILE_UPLOAD("file:upload", "文件上传"),
    FILE_DOWNLOAD("file:download", "文件下载"),
    FILE_DELETE("file:delete", "文件删除"),
    FILE_SHARE("file:share", "文件分享"),
    FILE_PREVIEW("file:preview", "文件预览"),
    
    // 用户管理权限
    USER_VIEW("user:view", "查看用户信息"),
    USER_EDIT("user:edit", "编辑用户信息"),
    USER_DELETE("user:delete", "删除用户"),
    
    // ==================== VIP权限 ====================
    
    // 团队管理权限
    TEAM_CREATE("team:create", "创建团队"),
    TEAM_VIEW("team:view", "查看团队"),
    TEAM_MANAGE("team:manage", "管理团队"),
    TEAM_DELETE("team:delete", "删除团队"),
    TEAM_INVITE("team:invite", "邀请团队成员"),
    TEAM_REMOVE_MEMBER("team:remove_member", "移除团队成员"),
    
    // 项目管理权限
    PROJECT_CREATE("project:create", "创建项目"),
    PROJECT_MANAGE("project:manage", "管理项目"),
    PROJECT_DELETE("project:delete", "删除项目"),
    PROJECT_ASSIGN_TASK("project:assign_task", "分配任务"),
    
    // 高级文件权限
    FILE_LARGE_UPLOAD("file:large_upload", "大文件上传(>100MB)"),
    FILE_BATCH_OPERATION("file:batch_operation", "批量文件操作"),
    FILE_VERSION_CONTROL("file:version_control", "文件版本控制"),
    
    // 协作权限
    COLLABORATION_CHAT("collaboration:chat", "团队聊天"),
    COLLABORATION_DOCUMENT("collaboration:document", "协作文档"),
    COLLABORATION_VIDEO_CALL("collaboration:video_call", "视频通话"),
    
    // ==================== 管理员权限 ====================
    
    // 系统管理权限
    ADMIN_USER_MANAGE("admin:user:manage", "用户管理"),
    ADMIN_TEAM_APPROVE("admin:team:approve", "团队审核"),
    ADMIN_SYSTEM_CONFIG("admin:system:config", "系统配置"),
    ADMIN_MONITOR("admin:monitor", "系统监控"),
    ADMIN_LOGS("admin:logs", "日志管理"),
    
    // 数据管理权限
    ADMIN_DATA_EXPORT("admin:data:export", "数据导出"),
    ADMIN_DATA_BACKUP("admin:data:backup", "数据备份"),
    ADMIN_DATA_RESTORE("admin:data:restore", "数据恢复");

    private final String code;
    private final String description;

    Permission(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据权限代码获取权限枚举
     */
    public static Permission fromCode(String code) {
        for (Permission permission : values()) {
            if (permission.getCode().equals(code)) {
                return permission;
            }
        }
        throw new IllegalArgumentException("未知的权限代码: " + code);
    }

    /**
     * 检查是否为VIP权限
     */
    public boolean isVipPermission() {
        return this == TEAM_CREATE || this == TEAM_MANAGE || this == TEAM_DELETE ||
               this == TEAM_INVITE || this == TEAM_REMOVE_MEMBER ||
               this == PROJECT_CREATE || this == PROJECT_MANAGE || this == PROJECT_DELETE ||
               this == PROJECT_ASSIGN_TASK || this == FILE_LARGE_UPLOAD ||
               this == FILE_BATCH_OPERATION || this == FILE_VERSION_CONTROL ||
               this == COLLABORATION_CHAT || this == COLLABORATION_DOCUMENT ||
               this == COLLABORATION_VIDEO_CALL;
    }

    /**
     * 检查是否为管理员权限
     */
    public boolean isAdminPermission() {
        return this.code.startsWith("admin:");
    }

    @Override
    public String toString() {
        return code;
    }
}
